#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool canPartition(vector<int>& nums) {
        int n = nums.size();
        int sum = 0;
        for (auto e : nums) sum += e;
        int t = sum / 2;
        if (sum % 2) return false;
        //  vector<vector<bool>>dp(n+1,vector<bool>(t+1));
        vector<bool>dp(t + 1);
        dp[0] = true;
        for (int i = 1; i <= n; i++)
            for (int j = t; j >= nums[i - 1]; j--)
            {

                dp[j] = dp[j] || dp[j - nums[i - 1]];
            }
        return dp[t];
    }
};